import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
import vuexPersist from "vuex-persist";

export default new Vuex.Store({
  state: {
    todo: [
      {
        title: "任务1",
        status: 0,
      },
      {
        title: "任务2",
        status: 1,
      },
      {
        title: "任务3",
        status: 0,
      },
      {
        title: "任务4",
        status: 1,
      },
      {
        title: "任务5",
        status: 0,
      },
    ],
  },
  mutations: {
    add(state, title) {
      state.todo.push({ title, status: 0 });
    },
    //往vuex中添加数据
    remove(state, index) {
      state.todo.splice(index, 1);
    },
    //删除
  },
  actions: {},
  modules: {},
  plugins: [
    new vuexPersist({
      storage: window.localStorage,
    }).plugin,
  ],
});
